<template>
	<view>
		<u-navbar titleStyle="font-size:40rpx;color:#333" :placeholder='true' title="退款售后" :autoBack="true">
		</u-navbar>
		<view class="padding32">
			<view class="lisbox whiteBox mt24" v-for="(item,index) in list" :key="index">
				<view @click="$my.go('/pages/my/order/orderDetail?refund_id='+item.refund_id)" >
					<view class="flexJBC fontS24">
						<view class="flex"> 
							<image :src="item.goods.store_image" mode="" style="width: 40rpx;height: 40rpx;border-radius: 50%;margin-right: 5rpx;"></image>
							<view class="">
								{{item.goods.store_name}}
							</view>
						</view>
						<view class="homeRed">
							{{item.status_text}}
						</view>
					</view>
					<view class="flexJBC" style="margin:24rpx auto 28rpx;align-items: flex-start;">
						<u-image :src="item.goods.store_image" width="80" height="80" radius='10' />
						<view class="fontS24" style="width: 65%;">
							<view class="flexJBC">
								<view class="elipes1 " style="width:70%;">
									{{item.goods.product_name}}
								</view>
								<view class="co9">
									¥{{item.goods.product_price}}
								</view>
							</view>
							<view style="margin-top: 10rpx;" class="flexJBC">
								<view class="co6">
									规格参数：{{item.goods.detail}}
								</view>
								<view class="co9">
									x{{item.goods.product_num}}
								</view>
							</view>
						</view>
					</view>
					<view class="yunxianfei fontS24" v-if="false">
						运费险：卖家赠送
					</view>
					<view class="flexJBC fontS24 co9" style="margin: 24rpx 0pt 16rpx;">
						<view class="">
							{{item.total_num}}种货品
						</view>
						<view class="flexJBC" style="margin-left:5rpx;width: 70%;">
							<view>总价:￥{{item.real_price}}</view>
							<view>运费:￥{{item.real_postage}}</view>
							<view>优惠￥0</view>
						</view>
					</view>
					<view class="fontS24" style="text-align: right;">
						实付款￥{{Number(item.total_product_price)}}
					</view>
					<view class="flexJBC" style="margin-top: 20rpx;">
						<view class="co9" @click.stop="del(item.refund_id)">
							删除订单
						</view>
						<view class="" v-if="item.refund_type==1 && item.status==3">
							退款金额：{{item.refund_price}}
						</view>
						<view>
							<!-- 状态 0:待审核 -1:审核未通过 1:待退货 2:待收货 3:已退款',  refund_type==1 退款 2是退货-->
							<view class="flex" v-if="item.status==0">
								<view class="btnClick1" @click.stop="cancel(item.refund_id)">
									取消退款
								</view>
							</view>
							<view class="flex" v-if="item.status==3  ">
								<view class="" v-if="item.refund_type==2">
									<view class="btnClick1 borderred homeRed"
										@click.stop="$my.go('/pages/my/order/fillRefundInfo?refund_id='+item.refund_id)">
										填写退货信息
									</view>
									<view class="btnClick1 borderred homeRed" style="margin-left: 24rpx;" @click="lookLogi(item)">
										查看物流
									</view>
								</view>
							</view>
							<view class="flex" v-if="item.status=='-1'">
								<view class="btnClick1 borderred homeRed"  @click.stop="resetall(item)">
									重新申请
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-empty v-if="list.length==0" mode="order" marginTop='20%'></u-empty>
		<u-loading-page loading-text="loading..." v-if='pageLoading' :loading='true' bgColor='#f5f5f5'></u-loading-page>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageLoading: true,
				list: [],
				page: 1,
			}
		},
		onShow() {
			this.page=1;
			this.list=[];
			this.getList()
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {
			// 重新申请
			resetall(item){
				this.$my.go('/pages/my/order/refund/refund?store='+JSON.stringify(item.goods) +'&refund_id='+item.refund_id)
			},
			// 查看物流
			lookLogi(item){
				// 详情
				uni.showLoading({
					title:'操作执行中...'
				})
				this.$my.post('/index/refund/order/details', {
					refund_id: item.refund_id,
				}).then(res => {
					uni.hideLoading();
					if (res.code == 200) {
						let express = res.data.express
						let order=res.data
						this.$my.go('/pages/my/order/logisticsDetail?express='+JSON.stringify(express.data)+'&order='+JSON.stringify(order))
					}else{
						this.$my.toast(res.message)
					}
				})
			},
			// 取消订单
			cancel(refund_id) {
				let _this = this
				uni.showModal({
					title: "",
					content: "确定要取消订单吗？",
					cancelText: '取消', // 取消按钮的文字   
					confirmText: '确认', // 确认按钮的文字   
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '取消中'
							})
							_this.$my.post('/index/refund/order/cancel', {
								refund_id
							}).then(res => {
								uni.hideLoading()
								_this.$my.toast(res.message)
								if (res.code == 200) {
									_this.page = 1;
									_this.list = [];
									_this.getList()
								}
							})
						}
					}
				})
			},
			// 删除订单
			del(refund_id) {
				let _this = this
				uni.showModal({
					title: "",
					content: "确定要删除吗",
					cancelText: '取消', // 取消按钮的文字   
					confirmText: '确认', // 确认按钮的文字   
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '删除中'
							})
							_this.$my.post('/index/refund/order/delete', {
								refund_id
							}).then(res => {
								uni.hideLoading()
								_this.$my.toast(res.message)
								if (res.code == 200) {
									_this.page = 1;
									_this.list = [];
									_this.getList()
								}
							})
						}
					}
				})
			},
			getList() {
				this.$my.get('/index/refund/order/list', {
					limit: 10,
					page: this.page
				}).then(res => {
					this.pageLoading = false
					if (res.code == 200){
						this.list = this.list.concat(res.data.data)
					}
				})
			}
		}
	}
</script>

